cc.Class({
    extends: cc.Component,

    properties: {
        itemNode: cc.Node,
        bagInfo: cc.Prefab,
    },

    onLoad () {
        this.itemBox = this.itemNode.parent;
        this.itemNode.parent = null;

        this.bagInfo = cc.instantiate(this.bagInfo);
        this.bagInfo.parent = this.node.parent;
        this.bagInfo = this.bagInfo.getComponent('ShopBagInfo');
    },

    init(data) {
        for(var i in data) {
            var node = cc.instantiate(this.itemNode);
            var item = node.getComponent('ShopBagItem');
            node.parent = this.itemBox;
            node.on('BAG_CLICK', this.onItemClick, this);
            item.init(data[i]);
        }
    },

    onItemClick(evt) {
        this.bagInfo.init(evt.detail);
        this.bagInfo.setPos(evt.target.convertToWorldSpaceAR(cc.v2(0, 0)));
    }
});
